//导入request.js 工具
import request from "@/utils/request";


//课程分类分页列表查询
export const courseTypePageListService = (params) => {
  return request.get('/coursecategory/findPageAll',{params:params});//两个params ，前面的是固定的，后面是自己传的参数
};
//课程分类列表查询
export const courseTypeListService = () => {
  return request.get('/coursecategory/findAll');
};

//课程分页列表查询
export const coursePageListService =(params)=>{
  return request.get('/courses/findPageAll',{params:params});
};

//课程列表查询
export const courseListService = () => {
  return request.get('/courses/findAll');
};


//创建课程分类
export const courseTypeAddService = (data) => {
  return request.post('/coursecategory/add',data);
};
//修改课程分类
export const courseTypeUpdateService = (data) => {
  return request.post('/coursecategory/update',data);
};
//删除课程分类
export const courseTypeDeleteService = (typeId) => {
  return request.delete('/coursecategory/delete', { params: { typeId } });
};
//批量删除课程分类
export const CourseTypeBatchdelService =(multipleSelection)=>{
  return request.put('/coursecategory/batchDelete', multipleSelection );
}


//创建课程 
export const courseAddService = (data) => {
  return request.post('/courses/add',data);
};
//课程修改
export const courseUpdateService = (data) => {
  return request.post('/courses/update',data);
};
//删除课程 
export const courseDeleteService = (courseId) => {
  return request.delete('/courses/delete', { params: { courseId } });
};
//批量删除课程
export const courseBatchDeleteService = (multipleSelection) => {
  return request.put('/courses/batchDelete', multipleSelection );
};
//根据课程id查询章节树结构
export const getChapterTreeByCourseIdService = (courseId) => {
  return request.get(`/chapters/tree/${courseId}`);
};
//添加章节 
export const insertChapterService = (chapter) => {
  return request.post('/chapters/insert', chapter);
};

//删除章节
export const deleteChapterService = (id) => {
  return request.delete(`/chapters/${id}`);
};
//修改章节
export const updateChapterService = ( chapter) => {
  return request.put(`/chapters/update`, chapter);
};
export const CourseTypeUploadService= (file) => {
  const formData = new FormData();
  formData.append('file', file);
  return request({
    url: "/coursecategory/upload",
    method: 'post',
    data: formData, // 使用 data 而不是 formData
    headers: {
      'Content-Type': undefined // 让 axios 自动设置 Content-Type
    }
  });
};

export const expCourseTypeServer =()=>{
  return request({
    url: "/coursecategory/export",
    method: 'get',
    responseType: 'blob' // 设置响应类型为blob
  });
}


export const CourseUploadService= (file) => {
  const formData = new FormData();
  formData.append('file', file);
  return request({
    url: "/courses/upload",
    method: 'post',
    data: formData, // 使用 data 而不是 formData
    headers: {
      'Content-Type': undefined // 让 axios 自动设置 Content-Type
    }
  });
};

export const expCourseServer =()=>{
  return request({
    url: "/courses/export",
    method: 'get',
    responseType: 'blob' // 设置响应类型为blob
  });
}
export const findAllCourseAndCountServer =()=>{
  return request.get('/courses/findAllCourseAndCount');
}
export const CoursefindAllCountServer =()=>{
  return request.get('/courses/findAllCount');
}

